$(function(){
		$("#doctorTable").datagrid({
			pagination:true,
			idField:"id"
		});
	})
	
	function setCondition(){
		var postData = {};
		var ids = $("#section").combobox("getValue");
		postData["section.id"] = ids;
		postData["user.id"]=$("#user").combobox("getValue");
		postData["registrationChargeType.id"]=$("#doctorType").combobox("getValue");
		console.log(postData);
		var kaishi = $("#kaishi").datebox("getValue");
		
		var jieshu = $("#jieshu").datebox("getValue");
		
		postData["shiftDate"] = kaishi;
		
		postData["dateclosed"] = jieshu;
		
		$("#doctorTable").datagrid("reload",postData);
		
	}
	
	//添加
		function addDoctor(){
			var d = $("<div></div>").appendTo("body");
			d.dialog({
				title:"添加药品",
				width:450,
				height:450,
				modal:true,
				href:"doctorRankClass/doctorRankClassForm",
				onClose:function(){$(this).dialog("destroy");},
				buttons:[{
					text:"确定",
					handler:function(){
						$("#doctorRankClassForm").form("submit",{
							url:"doctorRankClass/add",
							success:function(data){
								d.dialog("close");
								$("#doctorTable").datagrid("reload");
							}
						});
					}
				},{
					text:"取消",
					handler:function(){
						d.dialog("close");
					}
				}]
			});
		}
	//修改
	function editDoctor(){
		var row = $("#doctorTable").datagrid("getSelected");
		if(row == null){
			return;
		}
		$("#doctorTable").datagrid("clearSelections");
		$("#doctorTable").datagrid("selectRecord",row.id);
		var d = $("<div></div>").appendTo("body");
		d.dialog({
			title:"编辑",
			width:450,
			height:450,
			modal:true,
			href:"doctorRankClass/doctorRankClassForm",
			onClose:function(){$(this).dialog("destroy");},
			onLoad:function(){
				$.post("doctorRankClass/view",{id:row.id},function(data){
					$("#keshi").combobox("select",data.section.id);
					$("#doctorRankClassForm").form("load",data);
					$("#yisheng").combobox("select",data.user.id);
					$("#type").combobox("select",data.type.id);
					
				});
			},
			buttons:[{
				text:"确定",
				handler:function(){
					$("#doctorRankClassForm").form("submit",{
						url:"doctorRankClass/edit",
						success:function(data){
							d.dialog("close");
							$("#doctorTable").datagrid("reload");
						}
					});
				}
			},{
				text:"取消",
				handler:function(){
					d.dialog("close");
				}
			}]
		});
	}
	//修改请假状态
	function leaveDoctor(){
		var selRows = $("#doctorTable").datagrid("getSelections");
		if(selRows.length == 0){
			$.messager.alert("提示","确定要修改成请假状态吗？！","warning");
			return;
		}
		$.messager.confirm("提示","确定要修改成请假状态吗？",function(r){
			if(r){
				//3. 发送异步请求，带选中行的编号
				
				var postData = "";
				$.each(selRows,function(i){
					postData += "ids="+this.id;
					if(i < selRows.length - 1){
						postData += "&";
					}
				});
			
			$.post("doctorRankClass/leave",postData,function(data){
				if(data.result == true){
					//4. 修改请假成功后，刷新表格 reload
					$("#doctorTable").datagrid("reload");
				}
			});
			}
		});
	}
	//逻辑删除
	function deleteDoctor(){
			var selRows = $("#doctorTable").datagrid("getSelections");
			if(selRows.length == 0){
				$.messager.alert("提示","请选中要删除的数据行！","warning");
				return;
			}
			$.messager.confirm("提示","确定要删除选中的数据吗？",function(r){
				if(r){
					//3. 发送异步请求，带选中行的编号
					//拼接删除条件
					var postData = "";
					$.each(selRows,function(i){
						postData += "ids="+this.id;
						if(i < selRows.length - 1){
							postData += "&";
						}
					});
				}
				$.post("doctorRankClass/deletedoctorRankClass",postData,function(data){
					if(data.result == true){
						//4. 删除成功后，刷新表格 reload
						$("#doctorTable").datagrid("reload");
					}
				});
			});
		}
	
	function keshiFormatter(value,row,index){
		
		return row.section.name;
	};
	function userFormatter(value,row,index){
		if(row.user!=null){
			return row.user.name;
		}
	};
	function typeiFormatter(value,row,index){
			console.log(row);
			return row.registrationChargeType.typeName;
	}